<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
//        Commands\UserCommand::class,
    ];
    /**
     * Define the application's command schedule.
     *
     * @param \Illuminate\Console\Scheduling\Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {

        $schedule->call(function () {
            $now = now();
            $this->everyMinute();
            //每5分钟执行一次
            if ($now->minute % 5 == 0) {
                $this->everyFiveMinutes();
            }
            if ($now->hour == 0 && $now->minute == 0) {
                $this->daily();
            }

        })->everyMinute();

    }

    private function daily()
    {
        Log::emergency('daily');
        //每周日重新生成一次数据？
        if (now()->dayOfWeek == 0) {
        }

    }

    //处理laravel-2022-11-29.log文件过大的问题
    private function everyFiveMinutes()
    {

    }

    private function everyMinute()
    {
    }


    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }
}
